package com.fenghongzhang.day003;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private  long time=0;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.i(TAG, "onKeyDown: "+keyCode);
        if(keyCode == KeyEvent.KEYCODE_BACK){

        }
        return super.onKeyDown(keyCode, event);
    }

    public void send(View view) {

        Notification.Builder builder = new Notification.Builder(this);

        //必须的.
        builder.setSmallIcon(R.mipmap.ic_launcher);
//        builder.setContentTitle("标题");
//        builder.setContentText("通知的内容");


        //自定义布局
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notify_layout);

        builder.setCustomContentView(remoteViews);

        builder.setAutoCancel(true);
        builder.setWhen(System.currentTimeMillis());


        //锁屏通过
        builder.setVisibility(Notification.VISIBILITY_SECRET);

        //创建通知
        Notification build = builder.build();




        //有交互,能跳转
        Intent intent = new Intent(this, Main2Activity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
        builder.setContentIntent(pendingIntent);

        //震动,响铃,呼吸都用默认
        builder.setDefaults(Notification.DEFAULT_ALL);

        //让窗口弹出
        builder.setPriority(Notification.PRIORITY_MAX);



        //系统的服务
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        //发送
        manager.notify(2,build);



    }

    public void send2(View view) {

        Notification.Builder builder = new Notification.Builder(this);

        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentTitle("标题2");
        builder.setContentText("通知的内容2");

        builder.setAutoCancel(true);
        builder.setWhen(System.currentTimeMillis());

        //创建通知
        Notification build = builder.build();

        //系统的服务
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        //发送 相同代表更新
        manager.notify(3,build);


    }
}
